from pymysql import Connection as cc

con = None

try:
    con = cc(
        host='159.138.150.44',
        port=3306,
        user='root',
        password='lgifLZKX86EcInQw',
        database='halo',
        autocommit=True
    )
    # 创建游标
    cursors = con.cursor()
    sql = """
        SELECT
            msg_id,
            b_id,
            msg_type,
            title,
            url,
            view_type_cd,
            view_obj_id,
            create_time,
            operate,
            msg_addree
        FROM
            tianhao.business_msg2;
    """
    # 利用游标执行sql语句
    cursors.execute(sql)
    results = cursors.fetchall()
    print(results)
    for row in results:
        print(row)

except Exception as e:
    print('异常:', e)
finally:
    if con:
        con.close()
